package cn.wolfcode.rbac.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonUtils {
    public static String toJsonString(Object obj) {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(obj);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Object fromJson(String json,Class clz) {
        ObjectMapper mapper = new ObjectMapper();
        try {
            return mapper.readValue(json,clz);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }
}
